<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of teste
 *
 * @author Lucas Pinheiro
 */
class Query extends Admin {

    public function __construct() {
        parent::__construct();
        $this->load->language( 'logs/logs_layout' );
        $this->parser->set_title_pagina( 'Log', 'adm/log' );
        $this->parser->set_title( 'Log' );
        $this->load->model( 'log_querys_model' );
    }

    public function index() {
        $this->parser->site_view( 'logs/dashboard', array( ) );
    }

    public function consultar() {
        $params = array( );
        $params['CAMPOS'] = 'lq.*, u.username';
        $params['ORDERBY'] = 'id_log_querys DESC';
        $params['JOIN'][] = array(
            'TABELA' => $this->config->item( 'tblUser' ) . ' as u',
            'TIPO' => 'LEFT',
            'AND' => 'lq.id_user = u.id_user',
        );
        $b_consultar_total = $this->log_querys_model->total( $params );
        $params['LIMIT']['inicio'] = $this->uri->segment( 5, 0 );
        $params['LIMIT']['fim'] = $this->config->item( 'registro_por_pagina_cms' );
        $b_consultar = $this->log_querys_model->consultar( $params );

        $v_dados = array( );
        $v_dados['paginacao'] = '';
        $v_dados['logs'] = array( );
        $v_dados['lang_title_consulta'] = $this->lang->line( 'lang_title_consulta_querys' );

        if( $b_consultar != NULL ) {
            foreach( $b_consultar as $k => $v ) {
                $v_dados['logs'][$k]['id_log_querys'] = $v->id_log_querys;
                $v_dados['logs'][$k]['id_user'] = $v->username;
                $v_dados['logs'][$k]['query'] = $v->query;
                $v_dados['logs'][$k]['tipo'] = $v->tipo;
                $v_dados['logs'][$k]['data_hora_cadastro'] = formatarData( $v->data_hora_cadastro, array( 'formato' => 'd/m/Y H:i:s' ) );
            }
            $this->load->library( 'pagination' );
            $config['base_url'] = base_adm( 'logs/query/consultar/' );
            $config['total_rows'] = $b_consultar_total;
            $config['per_page'] = $params['LIMIT']['fim'];
            $config['uri_segment'] = 5;
            $this->pagination->initialize( $config );

            $v_dados['paginacao'] = $this->pagination->create_links();
        }
        $this->parser->site_view( 'lst_logs_query', $v_dados );
    }

}
